﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CashFlow.Db.DAL;
using CashFlow.Db.Entity;
using CashFlow.Db.Repository;

namespace CashFlow.Db.Implement.Repository
{
    public class FeeRepository : Repository<FeeEntity>, IFeeRepository
    {
        public IList<FeeAndUserInfoView> QueryByUserId(int userId)
        {
            using (var db = SqlSugarHelper.GetDb())
            {
                var ls = db.Queryable<FeeEntity>()
                    .InnerJoin<UserInfoEntity>((f, u) => f.UserId == u.Id)
                    .Where((f, u) => f.UserId == userId)
                    .OrderByDescending((f, u) => f.Date)
                    .Select((f, u) => new FeeAndUserInfoView
                    {
                        Fee = f,
                        UserInfo = u
                    })
                    .ToList();
                return ls;
            }
        }
    }
}
